package com.sx.service.basic;

import com.sx.basic.BasicService;
import com.sx.basic.exception.BasicException;
import com.sx.basic.impl.BasicServiceImpl;
import com.sx.entity.basic.FileEntity;
import com.sx.mapper.basic.FileMapper;
import com.sx.service.utils.FileUploadService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author AdinZ
 * @date 2020/11/16 11:36
 */
@Service
public class FileService extends BasicServiceImpl<FileMapper ,FileEntity>
        implements BasicService<FileEntity> ,IFileService{

    @Resource private FileUploadService fileUploadService;

    @Override
    public String upload(MultipartFile file) throws IOException {
        FileEntity upload = fileUploadService.upload(file);
        if(upload==null|| StringUtils.isEmpty(upload.getPath()))throw new BasicException("文件上传失败");
        this.save(upload);
        return upload.getPath();
    }
}
